/[gameplay]/gps/client.lua

https://gitlab.com/yasin3223/mtasa-resources · Lua · 90 lines · 53 code · 6 blank · 31 comment · 8 complexity · 9867ccd6476b0fa0d8a91c3d1c0ee3be MD5 · raw file

  1. local floor = math.floor
  2. addCommandHandler('path',
  3. function(command, node1, node2)
  4. if not tonumber(node1) or not tonumber(node2) then
  5. outputChatBox("Usage: /path node1 node2", 255, 0, 0)
  6. return
  7. end
  8. local path = server.calculatePathByNodeIDs(tonumber(node1), tonumber(node2))
  9. if not path then
  10. outputConsole('No path found')
  11. return
  12. end
  13. server.spawnPlayer(getLocalPlayer(), path[1].x, path[1].y, path[1].z)
  14. fadeCamera(true)
  15. setCameraTarget(getLocalPlayer())
  16. removeLinePoints ( )
  17. table.each(getElementsByType('marker'), destroyElement)
  18. for i,node in ipairs(path) do
  19. createMarker(node.x, node.y, node.z, 'corona', 5, 50, 0, 255, 200)
  20. addLinePoint ( node.x, node.y )
  21. end
  22. end
  23. )
  24. addCommandHandler('path2',
  25. function(command, tox, toy, toz)
  26. if not tonumber(tox) or not tonumber(toy) then
  27. outputChatBox("Usage: /path2 x y z (z is optional)", 255, 0, 0)
  28. return
  29. end
  30. local x,y,z = getElementPosition(getLocalPlayer())
  31. local path = server.calculatePathByCoords(x, y, z, tox, toy, toz)
  32. if not path then
  33. outputConsole('No path found')
  34. return
  35. end
  36. server.spawnPlayer(getLocalPlayer(), path[1].x, path[1].y, path[1].z)
  37. fadeCamera(true)
  38. setCameraTarget(getLocalPlayer())
  39. removeLinePoints ( )
  40. table.each(getElementsByType('marker'), destroyElement)
  41. for i,node in ipairs(path) do
  42. createMarker(node.x, node.y, node.z, 'corona', 5, 50, 0, 255, 200)
  43. addLinePoint ( node.x, node.y )
  44. end
  45. end
  46. )
  47. local function getAreaID(x, y)
  48. return math.floor((y + 3000)/750)*8 + math.floor((x + 3000)/750)
  49. end
  50. local function getNodeByID(db, nodeID)
  51. local areaID = floor(nodeID / 65536)
  52. return db[areaID][nodeID]
  53. end
  54. --[[
  55. addEventHandler('onClientRender', getRootElement(),
  56. function()
  57. local db = vehicleNodes
  58. local camX, camY, camZ = getCameraMatrix()
  59. local x, y, z = getElementPosition(getLocalPlayer())
  60. local areaID = getAreaID(x, y)
  61. local drawn = {}
  62. for id,node in pairs(db[areaID]) do
  63. if getDistanceBetweenPoints3D(x, y, z, node.x, node.y, z) < 300 then
  64. --[/[
  65. local screenX, screenY = getScreenFromWorldPosition(node.x, node.y, node.z)
  66. if screenX then
  67. dxDrawText(tostring(id), screenX - 10, screenY - 5)
  68. end
  69. --]/]
  70. --[/[
  71. for neighbourid,distance in pairs(node.neighbours) do
  72. if not drawn[neighbourid .. '-' .. id] then
  73. local neighbour = getNodeByID(db, neighbourid)
  74. dxDrawLine3D(node.x, node.y, node.z + 1, neighbour.x, neighbour.y, neighbour.z + 1, tocolor(0, 0, 200, 255), 3)
  75. drawn[id .. '-' .. neighbourid] = true
  76. end
  77. end
  78. --]/]
  79. end
  80. end
  81. end
  82. )
  83. --]]